<?php

require_once 'Zend/Validate/Abstract.php';

class Kzend_Validate_DateFormat extends Zend_Validate_Date
{
    const fromatDate = 'formatDate';
    const notCorrect = 'notCorrect';

    protected $_labelName = '';

    protected $_messageTemplates = array(
            self::fromatDate => 'Please enter "%labelName%" is "dd/mm/yyyy".',
            self::notCorrect => 'Please enter corrected "%labelName%".',);

    protected $_messageVariables = array(
            'labelName' => '_labelName',);

    public function __construct($labelName)
    {
        $this->_labelName = $labelName;
    }

    public function isValid($value)
    {
        $dt = explode('/', $value);
        $year = $dt[2];
        $month = $dt[1];
        $day = $dt[0];

        if (mb_strlen($value) < 8 || mb_strlen($value) > 10 || strlen($year) != 4 || strlen($month) < 1 || strlen($month) > 2 || strlen($day) < 1 || strlen($day) > 2) {
            $this->_error(self::fromatDate);
            return false;
        }

        if (!checkdate($month, $day, $year)) {
            $this->_error(self::notCorrect);
            return false;
        }
        return true;
    }

}
